<!--页面主要内容-->
<main class="lyear-layout-content">

    <div class="container-fluid p-t-15">

        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-toolbar d-flex flex-column flex-md-row">
                        <div class="toolbar-btn-action">
                            <a class="btn btn-success recoverys" href="javascript:void(0);"><i
                                    class="mdi mdi-window-close"></i> 批量恢复</a>
                            <a class="btn btn-danger dels" href="javascript:void(0);"><i
                                    class="mdi mdi-window-close"></i> 批量删除</a>
                        </div>

                        <form class="search-bar ml-md-auto" method="get" role="form">
                            <input type="hidden" name="search_field" id="search-field" value="title" />
                            <div class="input-group ml-md-auto">
                                <div class="input-group-prepend">
                                    {if $SearchField == 'title'}
                                    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"
                                        aria-haspopup="true" aria-expanded="false" id="search-btn">标题</button>
                                    {elseif $SearchField == 'catename'}
                                    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"
                                        aria-haspopup="true" aria-expanded="false" id="search-btn">分类名称</button>
                                    {else /}
                                    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"
                                        aria-haspopup="true" aria-expanded="false" id="search-btn">发布人</button>
                                    {/if}
                                    <div class="dropdown-menu" style="">
                                        <a class="dropdown-item" href="#!" data-field="title">标题</a>
                                        <a class="dropdown-item" href="#!" data-field="catename">分类名称</a>
                                        <a class="dropdown-item" href="#!" data-field="nickname">发布人</a>
                                    </div>
                                </div>
                                <input type="text" class="form-control" name="keyword" placeholder="{$keyword}">
                            </div>
                        </form>
                    </div>
                    <div class="card-body">

                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="check-all">
                                                <label class="custom-control-label" for="check-all"></label>
                                            </div>
                                        </th>
                                        <th>编号</th>
                                        <th>标题</th>
                                        <th>悬赏积分</th>
                                        <th>访问次数</th>
                                        <th>帖子状态</th>
                                        <th>附加功能</th>
                                        <th>发布人</th>
                                        <th>所属分类</th>
                                        <th>发布时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {foreach $PostList as $item}
                                    <tr>
                                        <td>
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input ids" name="ids[]"
                                                    value="{$item.id}" id="ids-{$item.id}">
                                                <label class="custom-control-label" for="ids-{$item.id}"></label>
                                            </div>
                                        </td>
                                        <td>{++$num}</td>
                                        <td>{$item.title}</td>
                                        <td>{$item.point}</td>
                                        <td>{$item.visit_total}</td>
                                        <td>{$item.accept ? '已采纳' : '未采纳'}</td>
                                        <td>{$item.state_text}</td>
                                        <td>{$item.user.nickname ? $item.user.nickname : ''}</td>
                                        <td>{$item.cate.name}</td>
                                        <td>{$item.createtime|date="Y-m-d H:i"}</td>
                                        <td>
                                            <div class="btn-group">
                                                <a class="btn btn-xs btn-default recovery" data-id="{$item.id}"
                                                    data-toggle="tooltip" data-original-title="恢复">
                                                    <i class="mdi mdi-file-eye"></i>
                                                </a>

                                                <a class="btn btn-xs btn-default del" data-id="{$item.id}"
                                                    data-toggle="tooltip" data-original-title="删除">
                                                    <i class="mdi mdi-window-close"></i>
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                    {/foreach}
                                </tbody>
                            </table>
                        </div>
                        {$PostList|raw}

                    </div>
                </div>
            </div>

        </div>

    </div>

</main>
<!--End 页面主要内容-->
<script>
    $(function () {
        $('.recovery').click(function () {
            $.confirm({
                title: '恢复数据',
                content: '确认恢复数据？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let postid = $(this).data('id')

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/post/recovery')}`,
                                data: {
                                    postid
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload();
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })


                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })
        })

        $('.recoverys').click(function () {
            $.confirm({
                title: '批量恢复数据',
                content: '确认批量恢复数据？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let postid = GetId()

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/post/recovery')}`,
                                data: {
                                    postid
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload()
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })


                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })

        })

        $('.del').click(function () {
            $.confirm({
                title: '删除',
                content: '确认删除？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let postid = $(this).data('id')

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/post/del')}`,
                                data: {
                                    postid,
                                    // 真实删除
                                    action: 'delete'
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload();
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })
                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })
        })

        $('.dels').click(function () {
            $.confirm({
                title: '批量删除',
                content: '确认批量删除？',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-info',
                        action: () => {
                            // 获取要删除的id
                            let postid = GetId()

                            $.ajax({
                                type: 'post',
                                url: `{:url('admin/post/del')}`,
                                data: {
                                    postid,
                                    action: 'delete'
                                },
                                dataType: 'json',
                                success: (result) => {
                                    if (result.code === 1) {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'success',
                                            onClose: function () {
                                                location.reload()
                                            }
                                        })
                                    } else {
                                        $.notify({
                                            message: result.msg,
                                        }, {
                                            delay: 1000,
                                            type: 'warning'
                                        })
                                    }
                                }
                            })


                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'btn-danger'
                    }
                }
            })

        })
    })
</script>